package com.wannengbang.cloudleader.homepage.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.ComplianceProgressBean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 消息列表
 */
public class TowComplianceProgressAdapter extends RecyclerView.Adapter<TowComplianceProgressAdapter.ViewHolder> {


    private List<ComplianceProgressBean.Data.TaskTwo.Lists> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;


    public TowComplianceProgressAdapter(List<ComplianceProgressBean.Data.TaskTwo.Lists> listsBeans) {
        this.listsBeans = listsBeans;

    }

    public void setOnCallBackListener(TowComplianceProgressAdapter.onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_compliance_progress, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ComplianceProgressBean.Data.TaskTwo.Lists dataBean = listsBeans.get(position);
        holder.tv_time.setText(dataBean.getMd());


        Log.e("position",position+"");
        Log.e("listsBeans",listsBeans.size()+"");
//        status 0 未考核 1未达标 2已达标
        int status = dataBean.getStatus();

        if (status==0){
            holder.iv_bc.setBackgroundResource(R.drawable.dot_hui);
        }else if (status==1){
            holder.iv_bc.setBackgroundResource(R.drawable.dot_red);
        }else {
            holder.iv_bc.setBackgroundResource(R.drawable.dot_lu);
        }

        if (position==listsBeans.size()-1){
            holder.v_lien.setVisibility(View.INVISIBLE);
        }else {
            holder.v_lien.setVisibility(View.VISIBLE);
        }

        if (position==0){
            holder.v_lien1.setVisibility(View.INVISIBLE);
        }else {
            holder.v_lien1.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.tv_time)
        TextView tv_time;

        @BindView(R.id.v_lien)
        View v_lien;
        @BindView(R.id.v_lien1)
        View v_lien1;
        @BindView(R.id.iv_bc)
        ImageView iv_bc;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int type, int position);
    }
}
